package com.lagou.edu.pojo;

import java.io.Serializable;

/**
 * 统一结果封装
 * @Author 梅松
 * @Date 2021/10/17 10:29
 */
public class Result<T> implements Serializable {

    /**
     * 响应状态码
     */
    private String code;

    /**
     * 响应消息
     */
    private String msg;
    /**
     * 响应数据
     */
    private Object data;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Result() {
    }

    public Result(String code,  String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(String code,String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 成功 返回默认成功信息
     *
     * @return
     */
    public static Result ok() {
        return new Result("200",  "操作成功", null);
    }

    /**
     * 成功 返回（data数据）成功信息
     *
     * @param data
     * @return
     */
    public static Result ok(Object data) {
        return new Result("200", "操作成功", data);
    }

    /**
     * 成功 返回自定义（消息、data数据）成功信息
     *
     * @param msg
     * @param data
     * @return
     */
    public static Result ok(String msg, Object data) {
        return new Result("200",  msg, data);
    }

    public static Result ok(String code,String msg, Object data) {
        return new Result(code, msg, data);
    }

    /**
     * 失败 返回默认失败信息
     *
     * @return
     */
    public static Result fail() {
        return new Result("500",  "操作失败", null);
    }

    /**
     * 失败 返回自定义（消息）失败信息
     *
     * @param msg
     * @return
     */
    public static Result fail(String msg) {
        return new Result("500", msg, null);
    }

    /**
     * 失败 返回自定义（消息、状态码）失败信息
     *
     * @param msg
     * @param data
     * @return
     */
    public static Result fail(String code, String msg) {
        return new Result("500",  msg, null);
    }


}
